# -*- encoding: utf-8 -*-
"""
File Name: format_problems
Description:
Author : 'lirui'
date: 10/24/2024
Contact: marjey_lee@163.com
Change Activity:
10/24/2024:
"""
import ll
from projects.monitoring.common.do.alarm import Alarm


def format_zabbix_alarms(original_alarms):
    alarm_lst = []
    for p in original_alarms:
        alarm = Alarm(
            timestamp=int(p['clock']),
            ip=p['host_name'],
            hostname=p['host_name'],
            severity=_get_severity(p['severity']),
            alarm_type='alarm',  # 'alarm,recovery'
            alarm_info=p['name'],
            note=None,
            recovery=False,
            recovery_time=None,
            manager_ip=p['zabbix_ip'],
            manager_port=p['zabbix_port'],
            alarm_source='内网zabbix告警'
        )
        alarm_lst.append(alarm)
    return alarm_lst


def _get_severity(severity_index):
    """
    """
    if str(severity_index) in ['0', '1', '2']:
        return 'remind'
    if str(severity_index) in ['3']:
        return 'warning'
    if str(severity_index) in ['4', '5']:
        return 'fatal'
    ll.get_logger().warning(f'Unknown severity_index: {severity_index}')
